<template>
    <div>
        <h1>权益显示</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>Id</td>
                    <td>权益名称</td>
                    <td>权益状态</td>
                    <td>操作</td>
                </tr>

                <tr v-for="itme in data.a":key="itme.Id">
                    <td>{{ itme.Id }}</td>
                    <td>{{ itme.Name }}</td>
                    <td>{{ itme.QYZT?"启用":"禁用" }}</td>
                    <td><input type="button" value="删除" @click="del(itme.Id)">
                        <input type="button" value="启用" @click="sta(itme.Id,itme.state=1)">
                        <input type="button" value="禁用" @click="sta(itme.Id,itme.state=0)">
                        <input type="button" value="修改" @click="xg(itme.Id)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref, reactive,onMounted} from 'vue'
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
const router=useRouter();
const route=useRoute();
let data:any=reactive({
    a:[],
})
onMounted(()=>{
    getlist();
})
//================修改=================
const xg=(id:any)=>{
    router.push({
        path:'/qyxg',
        query:{id:id}
    })
}
//================修改状态=================
const sta=(id:any,state:any)=>{
    axios({
        url:'/api/QY/Delete',
        method:'get',
        params:{
            id:id,
            state:state
        }
    })
    .then((res)=>{
        if(res.data>0)
    {
        alert("修改成功");
        getlist();
        return;
    }
    else
    {
        alert("修改失败");
        return;
    }
    })
    .catch((err)=>{
        console.log(err);
        
    })

}
//================删除=================
const del=(id:any)=>{
    axios({
        url:'/api/QY/Del',
        method:'delete',
        params:{id:id}
    })
    .then((res)=>{
        if(res.data>0)
    {
        alert("删除成功");
        getlist();
        return;
    }
    else
    {
        alert("删除失败");
        return;
    }
    })
    .catch((err)=>{
        console.log(err);
        
    })

}
//================显示=================
const getlist=()=>{
    axios({
        url:'/api/QY/GetShow',
        method:'get',
    })
    .then((res)=>{
        console.log(res);
        data.a=res.data
    })
    .catch((err)=>{
        console.log(err);
        
    })
}
</script>

<style scoped>

</style>